<?php

/*
This class defines standards, saves them as JSON data. The JSON data can be edited by users, to be extended (as can this class)
*/

class MetadataStandards{
    
    public $metaDirectoryPath; //full path to the metadata directory
    public $refineURI; //URI for Google Refine. Use the local host, not the reverse proxy for speed
    
    const directoryType = "standards"; //location of table metadata, stored as JSON files
    
    
    //get the required and optional fields for describing a dataset
    public function get_datasetMetadata(){
        
        $JSONstore = new JSONstore;
        $JSONstore->setDirectory(self::directoryType);
        
        $datasetMetadata = $JSONstore->read_parse_json("dataset-metadata");
        if(!$datasetMetadata){
            $this->datasetMetadata();
            $datasetMetadata = $JSONstore->read_parse_json("dataset-metadata");
        }
        
        return $datasetMetadata;
    }
    
    
        public function datasetMetadata(){
        
        $units = array("version" => 1,
                       "fields" => array(
                                        "0" => array("name" => "title",
                                              "required" => true,
                                              "multipleOK" => false,
                                              "note" => "Short descriptive name of the dataset",
                                              "type" => "medText",
                                              "subfields" => false
                                        ),
                                        "1" => array("name" => "creator",
                                              "required" => true,
                                              "multipleOK" => true,
                                              "note" => "Creator(s) of the dataset, agents for attribution",
                                              "type" => "medText",
                                              "subfields" => array(
                                                                   "1-0" => array(  "name" => "affiliation",
                                                                            "required" => true,
                                                                            "multipleOK" => true,
                                                                            "note" => "Organizational affiliation",
                                                                            "type" => "medText",
                                                                            "subfields" => false
                                                                    )
                                                            )
                                        ),
                                        
                                        "2" => array("name" => "abstract",
                                              "required" => true,
                                              "multipleOK" => false,
                                              "note" => "A narrative description of the dataset,
                                                        sufficiently detailed to guide informed users about the nature of the data.",
                                                "type" => "longText",
                                              "subfields" => false
                                        ),
                                        
                                        "3" => array("name" => "methodological notes",
                                              "required" => false,
                                              "multipleOK" => false,
                                              "note" => "A narrative describing data collection procedures and methods that may be 
                                                        significant in the interpretation and use of the dataset.",
                                                "type" => "longText",
                                              "subfields" => false
                                        ),
                                        
                                        "4" => array("name" => "short description",
                                              "required" => true,
                                              "multipleOK" => false,
                                              "note" => "A 140 character or less description of the dataset",
                                              "type" => "medText",
                                              "subfields" => false
                                        ),
                                        
                                        "5" => array("name" => "keyword",
                                              "required" => true,
                                              "multipleOK" => true,
                                              "note" => "A short descriptive term or short phrase",
                                              "type" => "shortText",
                                              "subfields" => false
                                        ),
                                        
                                        "6" => array("name" => "subject",
                                              "required" => true,
                                              "multipleOK" => true,
                                              "note" => "A short descriptive term or short phrase, from a controlled vocabulary",
                                              "type" => "shortText",
                                              "subfields" => array(
                                                                   "6-0" => array(  "name" => "vocabulary",
                                                                            "required" => true,
                                                                            "multipleOK" => false,
                                                                            "note" => "name of the controlled vocabulary",
                                                                            "type" => "medText",
                                                                            "subfields" => false
                                                                    ),
                                                                   "6-1" => array(  "name" => "vocabulary URI",
                                                                            "required" => true,
                                                                            "multipleOK" => false,
                                                                            "note" => "URI of the controlled vocabulary",
                                                                            "type" => "medText",
                                                                            "subfields" => false
                                                                    ),
                                                                   "6-2" => array(  "name" => "concept URI",
                                                                            "required" => false,
                                                                            "multipleOK" => false,
                                                                            "note" => "URI of the specific concept for the 'subject' ",
                                                                            "type" => "medText",
                                                                            "subfields" => false
                                                                    )
                                                            )
                                        ),
                                    
                                        "7" => array("name" => "related publication",
                                              "required" => false,
                                              "multipleOK" => true,
                                              "note" => "A bibliographic reference to related publications and published data",
                                              "type" => "medText",
                                              "subfields" => array(
                                                                   "7-0" => array(  "name" => "title",
                                                                            "required" => true,
                                                                            "multipleOK" => false,
                                                                            "note" => "title of the publication",
                                                                            "type" => "medText",
                                                                            "subfields" => false
                                                                    ),
                                                                   "7-1" => array(  "name" => "date",
                                                                            "required" => true,
                                                                            "multipleOK" => false,
                                                                            "note" => "date or year of the publication",
                                                                            "type" => "shortText",
                                                                            "subfields" => false
                                                                    ),
                                                                   "7-2" => array(  "name" => "author",
                                                                            "required" => true,
                                                                            "multipleOK" => true,
                                                                            "note" => "author(s) the publication",
                                                                            "type" => "medText",
                                                                            "subfields" => false
                                                                    ),
                                                                   "7-3" => array(  "name" => "publication URI",
                                                                            "required" => true,
                                                                            "multipleOK" => false,
                                                                            "note" => "URI of the publication ",
                                                                            "type" => "medText",
                                                                            "subfields" => false
                                                                    ),
                                                                   "7-4" => array(  "name" => "publication DOI",
                                                                            "required" => false,
                                                                            "multipleOK" => false,
                                                                            "note" => "DOI of the publication ",
                                                                            "type" => "shortText",
                                                                            "subfields" => false
                                                                    )
                                                            )
                                        )
                                )
                       );
        
        $json = json_encode($units, true);
        $JSONstore = new JSONstore;
        $JSONstore->setDirectory(self::directoryType);
        $JSONstore->save_json("dataset-metadata", $json);
        
    }
    
    
    
    
    
    public function referenceEntitiesMetadata(){
        
        $units = array("version" => 1,
                       "reference-entities" => array(
                                    array("name" => "Encyclopedia of Life", "domain" => "Biological taxa",
                                          "uri" =>"http://eol.org/"
                                    ),
                                    array("name" => "Pleiades Gazetteer", "domain" => "Ancient places",
                                          "uri" =>"http://pleiades.stoa.org/"
                                    ),
                                    array("name" => "Freebase", "domain" => "Misc.",
                                          "uri" =>"http://www.freebase.com/"
                                    )
                                )
                       );
        
        $json = json_encode($units, true);
        $JSONstore = new JSONstore;
        $JSONstore->setDirectory(self::directoryType);
        $JSONstore->save_json("reference-entities", $json);
        
    }
    
    
    
    public function saveVocabularies(){
        
        $vocabs =  array("version" => 1,
                        "vocabs" => array(   array (
                                                    "name" => "Biological Taxonomy Vocabulary",
                                                    "uri" => "http://purl.org/NET/biol/ns",
                                                    "props" => array(
                                                                        array(  "name" => "Has Biological Taxonomy",
                                                                                "uri" => "http://purl.org/NET/biol/ns#term_hasTaxonomy"
                                                                            )
                                                                    ) 
                                                    ),
                                             array (
                                                    "name" => "Concordia",
                                                    "uri" => "http://concordia.atlantides.org/",
                                                    "props" => array(
                                                                    array( "name" => "origin",
                                                                            "uri" => "http://gawd.atlantides.org/terms/origin"
                                                                    ),
                                                                    array( "name" => "findspot",
                                                                            "uri" => "http://gawd.atlantides.org/terms/findspot"
                                                                    )
                                                                )
                                                    )
                                        )
                                        
                       );
        
        $json = json_encode($vocabs, true);
        $JSONstore = new JSONstore;
        $JSONstore->setDirectory(self::directoryType);
        $JSONstore->save_json("vocabularies", $json);
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public function saveMetadata(){
        
        $units = array("version" => 1,
                       "standards" => array(
                        
                        
                                array(
                                "sType" => "Mass",
                                "units" => array(
                                    array("name" => "milligram", "abrv" => "mg",
                                          "uri" => "http://www.freebase.com/view/m/01x32f_",
                                          "reqType" => "float"),
                                    array("name" => "gram", "abrv" => "g",
                                          "uri" => "http://www.freebase.com/view/en/gram",
                                          "reqType" => "float"),
                                    array("name" => "kilogram", "abrv" => "kg",
                                          "uri" =>"http://www.freebase.com/view/en/kilogram",
                                          "reqType" => "float")
                                    )
                                ),
                                
                                array(
                                "sType" => "Length",
                                "units" => array(
                                     array("name" => "micrometer / micron", "abrv" => "µm",
                                          "uri" => "http://www.freebase.com/view/en/micrometer",
                                          "reqType" => "float"),
                                    array("name" => "millimeter", "abrv" => "mm",
                                          "uri" => "http://www.freebase.com/view/en/millimeter",
                                          "reqType" => "float"),
                                    array("name" => "centimeter", "abrv" => "cm",
                                          "uri" =>"http://www.freebase.com/view/en/centimeter",
                                          "reqType" => "float"),
                                    array("name" => "meter", "abrv" => "m",
                                          "uri" => "http://www.freebase.com/view/en/meter",
                                          "reqType" => "float"),
                                    array("name" => "kilometer", "abrv" => "km",
                                          "uri" => "http://www.freebase.com/view/en/kilometer",
                                          "reqType" => "float")
                                    )
                                ),
                                
                                array(
                                "sType" => "Area",
                                "units" => array(
                                    array("name" => "square meter", "abrv" => "m<sup>2</sup>",
                                          "uri" => "http://www.freebase.com/view/en/square_meter",
                                          "reqType" => "float"),
                                    array("name" => "hectare", "abrv" => "ha",
                                          "uri" =>"http://www.freebase.com/view/en/hectare",
                                          "reqType" => "float"),
                                    array("name" => "square kilometer", "abrv" => "km<sup>2</sup>",
                                          "uri" =>"http://www.freebase.com/view/en/square_kilometer",
                                          "reqType" => "float")
                                    )
                                ),
                                
                                array(
                                "sType" => "Volume",
                                "units" => array(
                                    array("name" => "milliliter", "abrv" => "mL",
                                          "uri" => "http://www.freebase.com/view/en/milliliter",
                                          "reqType" => "float"),
                                    array("name" => "liter", "abrv" => "L",
                                          "uri" =>"http://www.freebase.com/view/en/liter",
                                          "reqType" => "float"),
                                    array("name" => "cubic metre", "abrv" => "m<sup>3</sup>",
                                          "uri" =>"http://www.freebase.com/view/en/cubic_metre",
                                          "reqType" => "float")
                                    )
                                ),
                                
                                
                                array(
                                "sType" => "Geospatial",
                                "units" => array(
                                    array("name" => "latitude (WGS84)", "abrv" => "lat",
                                          "uri" => "http://www.w3.org/2003/01/geo/wgs84_pos#lat",
                                          "reqType" => "float"),
                                    array("name" => "longitude (WGS84)", "abrv" => "lon",
                                          "uri" =>"http://www.w3.org/2003/01/geo/wgs84_pos#long",
                                          "reqType" => "float"),
                                    array("name" => "altitude (WGS84)", "abrv" => "alt (m)",
                                          "uri" =>"http://www.w3.org/2003/01/geo/wgs84_pos#alt",
                                          "reqType" => "float")
                                    )
                                ),
                                
                                
                                array(
                                "sType" => "Chronology",
                                "units" => array(
                                    array("name" => "calendar year", "abrv" => "year",
                                          "uri" => "http://www.freebase.com/view/en/calendar_year",
                                          "reqType" => "integer"),
                                    array("name" => "calendar date", "abrv" => "date",
                                          "uri" =>"http://www.freebase.com/view/en/calendar_date",
                                          "reqType" => "calendar")
                                    )
                                )
                            )
                       );
        
        $json = json_encode($units, true);
        $JSONstore = new JSONstore;
        $JSONstore->setDirectory(self::directoryType);
        $JSONstore->save_json("common-units", $json);
        
    }
    
    

}//end class

?>